//
//  ThirdViewController.m
//  个人项目(豆瓣元旦作业)
//
//  Created by dllo on 16/1/7.
//  Copyright © 2016年 guoguo. All rights reserved.
//

#import "ThirdViewController.h"
#import "HGCollectionViewCell.h"
#import "UIImageView+WebCache.h"
@interface ThirdViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>




@end

@implementation ThirdViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
     self.navigationItem.title = @"电影";
    
    [self initCollectionView];
    
    NSLog(@"%@", _arrTH);
}

//创建UICollectionView
- (void)initCollectionView{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    //设置滚动方向
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //设置最小行间距
    layout.minimumLineSpacing = 10;
    //设置最小列间距u
    layout.minimumInteritemSpacing = 10;
    //设置四周距离
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    //设置item大小
    layout.itemSize = CGSizeMake((375 - 40) / 3, 180);
    
    
    
    //    创建collectionViewiew
    UICollectionView *collection = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    //签订代理人
    collection.delegate = self;
    collection.dataSource = self;
    collection.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:collection];
    
    //注册
    
    [collection registerClass:[HGCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    
}

#pragma mark  collectionView  Delegate

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _arrTH.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HGCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor redColor];
    NSDictionary *dic = _arrTH[indexPath.row][@"images"];
    [cell.image sd_setImageWithURL:[NSURL URLWithString:dic[@"medium"]] placeholderImage:[UIImage imageNamed:@"icon_date_blue@2x.png"]];
    
    cell.label.text = _arrTH[indexPath.row][@"orignal_title"];
    return cell;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
